<?php

/*
 * This function will show the document labels.
 * 
 * Created by: Peter Agno Jr.
 * Date created: November 5, 2011
 * 
 * In parameters : $mainDocId
 * Out parameters : document labels
 */

    // Add labels
    $labelQuery =
        "
            SELECT label
            FROM Document_Label as DL, Label as L
            WHERE documentId = '$mainDocId' AND DL.labelId = L.labelId
            ORDER BY label
        ";

    $labelResult = mysql_query($labelQuery) or die ('Error in query: $labelQuery. ' . mysql_error());

    // $totalLabel will be used for the commas of labels
    $totalLabel = mysql_num_rows($labelResult);
    $count = 1;

    while ( $labelRow = mysql_fetch_array($labelResult) ) {
        echo $labelRow['label'];

        if ( $count < $totalLabel ) 
            echo ", ";

        $count++;
    }
    mysql_free_result($labelResult);
?>
